const express=require('express');
const router = express.Router(); 
const bodyParser = require('body-parser');
const app = express()
app.use(bodyParser.urlencoded({extended:false}))
const userModel = require('../../model/userModel.js')
const util = require('../../utils/common.js')
router.post('/',(req,res)=>{
	let data = {
		user:req.body.user
	}
	let findResult = util.findData(userModel,data)
	findResult.then(result=>{
		if(result.length){
			res.send({
				'code':'200',
				'msg':'用户已存在'
			})
		}else{
			let userInfo = {
				user:req.body.user,
				pwd:req.body.pwd
			}
			let addResult = util.addData(userModel,userInfo)
			addResult.then(result=>{
				if(result){
					res.send({
						'code':'200',
						'msg':'添加用户成功'
					})
				}
			})
		}
	})
})
module.exports = router;